﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using MySql.Data;
using MySql.Data.MySqlClient;

namespace doris.Ticketuser
{
    public partial class userMain : System.Web.UI.Page
    {
       
         MySqlConnection con;
         MySqlCommand cmd;
        
        protected void Page_Load(object sender, EventArgs e)
        {

            setConnection();
            if (Session["ticketID"] == null)
            {
                Button1.Visible = false;
            }


            String CustID = Membership.GetUser().ProviderUserKey.ToString();
            String username = "";
            String fullname = "";
            String adress   = "";
            String postcode = "";
            String email    = "";
            String userID = "";
           

            MySqlDataReader reader;
            cmd = new MySqlCommand("SELECT UserID, Username, Email, Fullname, Adress, Postcode FROM user", con);

            try
            {
                con.Open();
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    if (CustID == reader["UserID"].ToString())
                    {
                        username = reader["UserName"].ToString();
                        fullname = reader["Fullname"].ToString();
                        adress   = reader["Adress"].ToString();
                        postcode = reader["Postcode"].ToString();
                        email    = reader["Email"].ToString();
                        userID = reader["UserID"].ToString();
                    }
                }

                Session["username"]  = username;
                Session["fullname"]  = fullname;
                Session["adress"]    = adress;
                Session["postcode"]  = postcode;
                Session["email"]     = email;
                Session["UserID"]    = userID;
                if (Session["Email"] != null)
                {
                   
                     Label1.Text = "Username: "+(String)Session["username"];
                    //Label1.Text = "UserID:  " + Session["UserID"].ToString();                  
                       
                }

            }

            catch (Exception ex)
            {
                Response.Write(ex.ToString());
            }
            finally
            {
                con.Close();
            }
        }
        
        public void setConnection()
        {
            con = new MySqlConnection(WebConfigurationManager.ConnectionStrings["localConnectionString"].ConnectionString);
        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
           Session["ticketID"] = GridView1.SelectedRow.Cells[1].Text;
        }

        protected void Button1_Click(object sender, EventArgs e)
        {

        }

        protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
        {
            if (e.Item.Value.ToString() == "NewTicket")
            {
                Response.Redirect("newTicket.aspx");
            }

            if (e.Item.Value.ToString() == "EditUser")
            {
                Response.Redirect("EditUser.aspx");
            }

            if (e.Item.Value.ToString() == "Logout")
            {
                Response.Redirect("LoggedOut.aspx");
            }
            
            
        }

      
      
      

    }
}